#include <my_head.h>
int main(int argc, char const *argv[])
{
    if(3 != argc){
        printf("Usage:%s src_file dest_file\n", argv[0]);
        return -1;
    }
    int fd_r = 0;
    if(-1 == (fd_r = open(argv[1],O_RDONLY)))
        ERR_LOG("open error");
    off_t src_file_size = lseek(fd_r, 0, SEEK_END);
    if (-1 == src_file_size ) {
        ERR_LOG("lseek error");
    }
    close(fd_r);
    int fd_w = 0;
    if(-1 == (fd_w = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0664)))
        ERR_LOG("open error");
    close(fd_w);
    pid_t pid = fork();
    char buff[65] = {0};
    int nbytes = 0;

    if(-1 == (fd_r = open(argv[1],O_RDONLY)))
        ERR_LOG("open error");

    if(-1 == (fd_w = open(argv[2],O_WRONLY)))
        ERR_LOG("open error");
    if(-1 == pid)
        ERR_LOG("fork error");
    if(0<pid){
        lseek(fd_r,0,SEEK_SET);
       while (0<(nbytes = read(fd_r,buff,sizeof(buff)/2)))
       {
            write(fd_w,buff,nbytes);
       } 
    }else if(0 == pid){
        lseek(fd_r,0,SEEK_CUR);
        while (0<(nbytes = read(fd_r,buff,sizeof(buff)-sizeof(buff)/2)))
       {
            write(fd_w,buff,nbytes);
       } 
    }
    close(fd_r);
    close(fd_w);
    return 0;
}
